import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from "@vue/runtime-core";
import {Tag} from "ant-design-vue";

export const columns: BasicColumn[] = [
  {
    title: '支付金额',
    dataIndex: 'payAmount',
    customRender: ({record}) => {
      return record.payAmount / 100;
    },
  },
  {
    title: '退款金额',
    dataIndex: 'refundAmount',
    customRender: ({record}) => {
      return record.refundAmount / 100;
    },
  },
  {
    title: '商户名称',
    dataIndex: 'mchName',
  },
  {
    title: '支付订单号',
    dataIndex: 'orderNo',
  },
  {
    title: '渠道支付单号',
    dataIndex: 'channelPayOrderNo',
  },
  {
    title: '退款订单号',
    dataIndex: 'refundNo',
  },
  {
    title: '商户退款单号',
    dataIndex: 'mchRefundNo',
  },
  {
    title: '渠道退款订单号',
    dataIndex: 'channelRefundNo',
  },
  {
    title: '退款状态',
    dataIndex: 'refundStatus',
    customRender: ({record}) => {
      let color = 'volcano';
      let text = '';
      switch (record.orderStatus) {
        case 0:
          color = 'blue';
          text = '订单生成';
          break;
        case 1:
          color = 'orange';
          text = '退款中';
          break;
        case 2:
          color = 'green';
          text = '退款成功';
          break;
        case 3:
          text = '退款失败';
          break;
        case 4:
          text = '退款任务关闭';
          break;
        default:
          text = '未知';
      }
      return h(Tag, {color: color}, () => text);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'refundNo',
    label: '退款订单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'orderNo',
    label: '支付订单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'channelPayOrderNo',
    label: '渠道支付单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'mchRefundNo',
    label: '商户退款单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'channelRefundNo',
    label: '渠道退款订单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'refundStatus',
    label: '退款状态',
    component: 'Select',
    componentProps: {
      options: [
        {label: '订单生成', value: 0},
        {label: '退款中', value: 1},
        {label: '退款成功', value: 2},
        {label: '退款失败', value: 3},
        {label: '退款任务关闭', value: 4},
      ],
    },
    colProps: {span: 6},
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'tenantId',
    label: '租户编号',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundNo',
    label: '退款订单号（支付系统生成订单号）',
    component: 'Input',
    required: true,
  },
  {
    field: 'orderNo',
    label: '支付订单号',
    component: 'Input',
    required: true,
  },
  {
    field: 'channelPayOrderNo',
    label: '渠道支付单号',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    required: true,
  },
  {
    field: 'isvNo',
    label: '服务商号',
    component: 'Input',
    required: true,
  },
  {
    field: 'appId',
    label: '应用ID',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchName',
    label: '商户名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchType',
    label: '类型: 1-普通商户, 2-特约商户(服务商模式)',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchRefundNo',
    label: '商户退款单号（商户系统的订单号）',
    component: 'Input',
    required: true,
  },
  {
    field: 'wayCode',
    label: '支付方式编码',
    component: 'Input',
    required: true,
  },
  {
    field: 'channelCode',
    label: '支付渠道编码',
    component: 'Input',
    required: true,
  },
  {
    field: 'payAmount',
    label: '支付金额,单位分',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundAmount',
    label: '退款金额,单位分',
    component: 'Input',
    required: true,
  },
  {
    field: 'currency',
    label: '三位货币代码,人民币:CNY',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundStatus',
    label: '退款状态:0-订单生成,1-退款中,2-退款成功,3-退款失败,4-退款任务关闭',
    component: 'Input',
    required: true,
  },
  {
    field: 'clientIp',
    label: '客户端IP',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundReason',
    label: '退款原因',
    component: 'Input',
    required: true,
  },
  {
    field: 'channelRefundNo',
    label: '渠道退款订单号',
    component: 'Input',
    required: true,
  },
  {
    field: 'errCode',
    label: '渠道错误码',
    component: 'Input',
    required: true,
  },
  {
    field: 'errMsg',
    label: '渠道错误描述',
    component: 'Input',
    required: true,
  },
  {
    field: 'channelExtra',
    label: '特定渠道发起时额外参数',
    component: 'Input',
    required: true,
  },
  {
    field: 'notifyUrl',
    label: '通知地址',
    component: 'Input',
    required: true,
  },
  {
    field: 'extParam',
    label: '扩展参数',
    component: 'Input',
    required: true,
  },
  {
    field: 'successTime',
    label: '订单退款成功时间',
    component: 'Input',
    required: true,
  },
  {
    field: 'expiredTime',
    label: '退款失效时间（失效后系统更改为退款任务关闭状态）',
    component: 'Input',
    required: true,
  },
];
